package lian_xi;

import java.util.concurrent.ThreadFactory;

class myThreadFactory implements ThreadFactory{
    private static final ThreadFactory INSTANCE = new myThreadFactory();
    private static final String TITLE = "MyThread-";
    private static int count = 0;
    private  myThreadFactory(){}
    public static ThreadFactory getInstance(){
        return INSTANCE;
    }

    @Override
    public Thread newThread(Runnable r) {
        return new Thread(r,TITLE+count++);
    }
}
//线程工厂类
public class ThreadDemo1 {
    public static void main(String[] args) {
        Thread t1 = myThreadFactory.getInstance().newThread(()->{
            System.out.println("【线程启动】"+Thread.currentThread().getName());
        });
        t1.start();
    }
}
